<?php
session_start();

?>
<?php
	
	include_once('config/db_conn.php');
	include_once('db_config/db_gigs.php');
	include_once('db_config/db_user.php');
	include_once('db_config/db_order_payment.php');
	include_once('db_config/db_websetting.php');
	include_once('db_config/db_multiple_gigs.php');

	$multiple_gigs =new multipleGigs();
		
	$websetting= new websetting();
	$websetting_id = '1';
	$rs_websetting=$websetting->uniq_websettings('websetting_id',$websetting_id);
	$data_websetting=mysql_fetch_array($rs_websetting);
	
	$user=new user();		
	$gigs=new gigs();
	$rs_gigs=$gigs->uniq_gigs_list('gigs_title',$_POST['item_name']);
	$data_gigs = mysql_fetch_array($rs_gigs);
	$order_payment=new order_payment();
	
	if($_POST)
	{
		$comm_amt = ($_POST['mc_gross'] * $data_websetting['commission_amt'])/100;
		$order_amt = $_POST['mc_gross'] - $comm_amt;
        $_POST['mc_gross'] = $order_amt;
		$_POST['payment_gross'] = $order_amt;
		$_POST['custom'] = 'nil';
		if ($_POST['pending_reason'] == '')
			$_POST['pending_reason']='Nil';

		$array_1=array("seller_id"=>$data_gigs['user_id'],"buyer_id"=>$_SESSION['user_id'],"order_status_date"=>date('Y-m-d'),"mc_gross"=>$_POST['mc_gross'],"protection_eligibility"=>$_POST['protection_eligibility'],"payment_gross"=>$_POST['payment_gross'],"address_status"=>$_POST['address_status'],"payer_id"=>$_POST['payer_id'],"tax"=>$_POST['tax'],"address_street"=>$_POST['address_street'],"payment_date"=>$_POST['payment_date'],"payment_status"=>$_POST['payment_status'],"charset"=>$_POST['charset'],"address_zip"=>$_POST['address_zip'],"first_name"=>$_POST['first_name'], "mc_fee"=>$_POST['mc_fee'],"address_country_code"=>$_POST['address_country_code'],"address_name"=>$_POST['address_name'],"notify_version"=>$_POST['notify_version'],"custom"=>$_POST['custom'],"payer_status"=>$_POST['payer_status'],"business"=>$_POST['business'],"address_country"=>$_POST['address_country'],"address_city"=>$_POST['address_city'],"quantity"=>$_POST['quantity'],"payer_email"=>$_POST['payer_email'],"verify_sign"=>$_POST['verify_sign'],"txn_id"=>$_POST['txn_id'],"payment_type"=>$_POST['payment_type'],"last_name"=>$_POST['last_name'],"address_state"=>$_POST['address_state'],"receiver_email"=>$_POST['receiver_email'],"payment_fee"=>$_POST['payment_fee'],"receiver_id"=>$_POST['receiver_id'],"pending_reason"=>$_POST['pending_reason'],"txn_type"=>$_POST['txn_type'],"item_name"=>$_POST['item_name'],"mc_currency"=>$_POST['mc_currency'],"item_number"=>$_POST['item_number'],"residence_country"=>$_POST['residence_country'],"receipt_id"=>$_POST['receipt_id'],"test_ipn"=>$_POST['test_ipn'],"transaction_subject"=>$_POST['transaction_subject'],"handling_amount"=>$_POST['handling_amount'],"shipping"=>$_POST['shipping'],"merchant_return_link"=>addslashes($_POST['merchant_return_link']));
		$array_m=array_merge($array_1);
		$order_payment->dataInsert('ninerr_order_payment',$array_m);
		
		##################################################################
									/*Mail send to seller*/
		##################################################################
		$rs_uniq_user=$user->uniq_user_list('user_id',$data_gigs['user_id']);
		$data_uniq_user=mysql_fetch_array($rs_uniq_user);
		
		$rs_uniq_user1=$user->uniq_user_list('user_id',$_SESSION['user_id']);
		$data_uniq_user1=mysql_fetch_array($rs_uniq_user1);
		
		$to_mail=$data_uniq_user['user_primary_email'];
		$subject =ucfirst(SITE_NAME).': Sell Confirmation';

		$mail_table = '
		<table width="600" border="0">

		  <tr>
			<td width="600" align="center"><h3>Thank you for joining '.ucfirst(SITE_NAME).'!</h3></td>
		  </tr>
		  <tr>
			<td width="600" align="left"><b>Buyer Information:<b><br />
				Name: '.$data_uniq_user1['user_name'].'<br />
				Email: '.$data_uniq_user1['user_primary_email'].'<br />
				Location: '.$data_uniq_user1['user_location'].'<br />
				Contact Number: '.$data_uniq_user1['user_office_phone'].'<br />
			</td>
		  </tr>
		  <tr>
			<td width="600" align="left"><b>Gigs Information:<b><br />
				Name: '.$data_gigs['gigs_title'].'<br />
				Description: '.$data_gigs['gigs_description'].'<br />
				Rate: '.$data_gigs['gigs_rate'].'<br />
				Days to Complete: '.$data_gigs['gigs_maxi_days_to_comp'].'<br />
			</td>
		  </tr>
		</table>';


		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
		$headers.="To: ".$to_mail."\r\n";
		$headers.="From: Administrator <noreply@".SITE_MAIL.">\r\n";
		mail($to_mail, $subject, $mail_table, $headers);
		##################################################################
		
		##################################################################
									/*Mail send to Buyer*/
		##################################################################
		
		$to_mail=$data_uniq_user1['user_primary_email'];
		$subject =ucfirst(SITE_NAME).': Buy Confirmation';

		$mail_table = '
		<table width="600" border="0">

		  <tr>
			<td width="600" align="center"><h3>Thank you for joining '.ucfirst(SITE_NAME).'!</h3></td>
		  </tr>
		  <tr>
			<td width="600" align="left">
				Seller Name: '.$data_uniq_user['user_name'].'<br />
				Seller Email: '.$data_uniq_user['user_primary_email'].'<br />
				Seller Location: '.$data_uniq_user['user_location'].'<br />
				Seller Contact Number: '.$data_uniq_user['user_office_phone'].'<br />
			</td>
		  </tr>
		  <tr>
			<td width="600" align="left"><b>Gigs Information:<b><br />
				Name: '.$data_gigs['gigs_title'].'<br />
				Description: '.$data_gigs['gigs_description'].'<br />
				Rate: '.$data_gigs['gigs_rate'].'<br />
				Days to Complete: '.$data_gigs['gigs_maxi_days_to_comp'].'<br />
			</td>
		  </tr>
		</table>';


		$headers  = "MIME-Version: 1.0\r\n";
		$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
		$headers.="To: ".$to_mail."\r\n";
		$headers.="From: Administrator <noreply@".SITE_MAIL.">\r\n";
		mail($to_mail, $subject, $mail_table, $headers);
		##################################################################
		
		
		
	}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title><?php echo $data_websetting['change_title']; ?></title>
<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="javascript/jquery.min.js"></script>
<script type="text/javascript" src="javascript/jquery.simplemodal.js"></script>
<script type="text/javascript" src="javascript/init.js"></script>
<script type="text/javascript" src="javascript/init1.js"></script>
<script src="javascript/main.js" type="text/javascript"></script>
<script language="javascript" type="text/javascript">

	/* this is just a simple reload; you can safely remove it; remember to remove it from the image too */
	
	function reloadCaptcha()
	{
		document.getElementById('captcha').src = document.getElementById('captcha').src+ '?' +new Date();
	}
</script>
<script language="javascript">
function openCenteredWindow(url) {
	parms = 'menubar=no,width=600,height=500,toolbar=no'
	name = "facebook_share"
	height=500
	width=600
   var left = Math.floor( (screen.width - width) / 2);
   var top = Math.floor( (screen.height - height) / 2);
   var winParms = "top=" + top + ",left=" + left + ",height=" + height + ",width=" + width;
   if (parms) { winParms += "," + parms; }
   var win = window.open(url, name, winParms);
   if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
   return win;
}
</script>
<link type='text/css' href='css/stylesheet.css' rel='stylesheet' media='screen' />
<link type='text/css' href='css/basic.css' rel='stylesheet' media='screen' />
</head>
<body>
<div id="container">

<!--HEADER AREA-->
<?php include('header.php')?>
<!--HEADER AREA END-->
<div class="body_cont">
<div class="body_cont_top">
</div>
<div class="body_cont_center">
<div class="left_cont">
  
<div class="tweet_bx">
Thanks for paying!
</div>

<div class="tweet_bx">
  <div class="tweet_bx_left"></div>

</div>
</div>
<?php include('right.php'); ?>
</div>
<div class="body_cont_bottom">
</div>
</div>
<?php
include('footer.php');
 ?>

</div>
</body>
</html>